package com.example.springboot.thread;

public class RunableRuning implements Runnable {
    private int count = 5;

    @Override
    public synchronized void run() {
        while (count > 0) {
            count--;
            System.out.println(Thread.currentThread().getName() +
                    " 卖出一张票，现有票：" + count);
        }
    }

    public static void main(String[] args) {
        //实现runnable方式，开启多个线程，实现资源共享
        RunableRuning runableRuning = new RunableRuning();
        new Thread(runableRuning).start();
        new Thread(runableRuning).start();
    }
//    结果
//    Thread-0 卖出一张票，现有票：4
//    Thread-0 卖出一张票，现有票：3
//    Thread-0 卖出一张票，现有票：2
//    Thread-0 卖出一张票，现有票：1
//    Thread-0 卖出一张票，现有票：0
}
